#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;
using i64 = int64_t;

template <typename T>
class ObjectPool {
private:
  char *pool;
  vector<T*> free_list;

public:
  ObjectPool(size_t capacity) {
    pool = new char[capacity * sizeof(T)];
    free_list.reserve(capacity);

    for (size_t i = 0; i < capacity; i++) {
      T* ptr = reinterpret_cast<T*>(pool + i * sizeof(T));
      free_list.push_back(ptr);
    }
  }
  template <typename... Args>
  T* allocate(Args&&... args) {
    if (free_list.empty()) throw std::bad_alloc{};
    T* ptr = free_list.back();
    free_list.pop_back();
    return new (ptr) T(std::forward<Args>(args)...);
  }
  void deallocate(T* p) {
    if (!p) return;
    p->~T();
    free_list.push_back(p);
  }
};

struct List {
  struct Node {
    int val;
    Node *next, *prev;
  };
  vector<Node*> nodes;
  vector<int> in_list;
  ObjectPool<Node> pool;
  List(int n) : pool(n + 2) {
    in_list.resize(n + 1, true);
    nodes.resize(n + 1);
    for (int i = 0; i <= n; i ++) {
      nodes[i] = pool.allocate(i, nullptr, nullptr);
    }
    for (int i = 0; i <= n; i ++) {
      if (i != 0) nodes[i]->prev = nodes[i - 1];
      if (i != n) nodes[i]->next = nodes[i + 1];
    }
  };
  void insert_before(int x, int y) {
    if (x == y || !in_list[x] || !in_list[y]) return;
    Node* X = remove_from_list(x);
    Node* Y = nodes[y];
    Node* pre = Y->prev;
    pre->next = X;
    X->prev = pre;
    X->next = Y;
    Y->prev = X;
  }
  void insert_after(int x, int y) {
    if (x == y || !in_list[x] || !in_list[y]) return;
    Node* X = remove_from_list(x);
    Node* Y = nodes[y];
    Node* nxt = Y->next;
    if (nxt) nxt->prev = X;
    X->next = nxt;
    X->prev = Y;
    Y->next = X;
  }
  Node* remove_from_list(int x) {
    if (!in_list[x]) return nullptr;
    Node* cur = nodes[x];
    Node* pre = cur->prev, *nxt = cur->next;
    pre->next = nxt;
    if (nxt) nxt->prev = pre;
    return cur;
  }
  void remove(int x) {
    Node *node = remove_from_list(x);
    pool.deallocate(node);
    // delete node;
    in_list[x] = false;
  }
  void output() {
    if (!nodes[0]->next) {
      cout << "Empty!" << endl;
      return;
    }
    for (Node* cur = nodes[0]->next; cur; cur = cur->next) {
      cout << cur->val << ' ';
    }
    cout << endl;
  }
};
int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  List list(n);
  while (m --) {
    int op, x, y;
    cin >> op >> x;
    if (op == 1) {
      cin >> y;
      list.insert_before(x, y);
    } else if (op == 2) {
      cin >> y;
      list.insert_after(x, y);
    } else if (op == 3) {
      list.remove(x);
    }
  }
  list.output();
}